package com.time.workshop.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.time.workshop.R;
import com.time.workshop.SuperActivity;
import com.time.workshop.bean.ShopList;
import com.time.workshop.utils.CommonUtils;

public class DingZuoAdapter extends BaseAdapter{
	private Context context;
	private List<ShopList> list;
	private LayoutInflater inflater;
	private ViewHolder holder = null;
	public SuperActivity mSuperActivity;
	
	public DingZuoAdapter(Context context, List<ShopList> list) {
		this.context = context;
		this.list = list;
		this.mSuperActivity = (SuperActivity) context;
		inflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_dingzuo_list, null);
			holder.item_layout = (RelativeLayout) convertView.findViewById(R.id.item_layout);
			holder.bg_ImageView = (ImageView) convertView.findViewById(R.id.bg_ImageView);
			holder.nameTextView = (TextView) convertView.findViewById(R.id.nameTextView);
			holder.addressTextView = (TextView) convertView.findViewById(R.id.addressTextView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.nameTextView.setText(list.get(position).getNAME());
		holder.addressTextView.setText(list.get(position).getADDRESS());
		if (!CommonUtils.isNull_nie(list.get(position).getPIC_URL())) {
			ImageLoader.getInstance().displayImage(list.get(position).getPIC_URL(), holder.bg_ImageView, mSuperActivity.getDisplayOption());
		}
		return convertView;
	}
	public final class ViewHolder {
		private TextView nameTextView,addressTextView;
		private ImageView bg_ImageView;
		private RelativeLayout item_layout;
	}
	@Override
	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
	}
}
